<?php
use think\Log;
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
/**
 * 判断手机号是否注册
 * @param unknown $telphone
 */
function isset_user($telphone){
    $res = db("member")->where(['telphone'=>$telphone])->find();
    
    if ($res){
        return true;
    }else{
        return false;
    }
}
/**
 * 校验用户账号密码
 * @param unknown $telphone
 * @param unknown $password
 */
function check_user($telphone,$password){
    $res = db("member")->where(['telphone'=>$telphone])->find();
    if ($res['password']==md5($password)){
        return $res;
    }else {
        return false;
    }
}
/**
 * 校验管理员登录
 */
function check_login($username,$password){
    $res = db("manager")->where(["username"=>$username])->find();
    if ($res['password']==md5($password)){
        return $res;
    }else {
        return false;
    }
    
}
/**
 * 性别转换函数
 * @param unknown $int
 * @return string
 */
function sextool($int){
    $str = "未定义";
    switch ($int){
     case 0:
        $str = "未知";
        break;
     case 1:
        $str = "男";
        break;
     case 2:
         $str = "女";
         break;
    }
    return $str;
}

function statustool($int){
    $str = "未定义";
    switch ($int){
        case 0:
            $str = "待审核";
            break;
        case 1:
            $str = "正常";
            break;
        case -1:
            $str = "审核未通过";
            break;
    }
    return $str;
}

function is_normal_user(){
    
}

function setSession($name,$value){
    return session($name,$value);
}


function getSession($name){
    return session($name);
}
/**
 * 教练工具函数根据id转换成名称
 * @param unknown $tid
 */
function coachtool($tid){
   
    $name = "";
    if ($tid){
        $res = db("member")->field("name")->find($tid);
        $name = $res['name'];
    }
    return $name;
}


function headerpictool($tid) {
    $res = db("member")->field("headerpic")->find($tid);
    return $res['headerpic'];
}

function contenttool($tid) {
    $res = db("member")->field("content")->find($tid);
    return $res['content'];
}

/**
 * 
 * @param unknown $id
 * @param unknown $pwd
 */
function checkpwd($id,$pwd) {
    $res = db("member")->field("password")->find($id);
    if ($res['password'] == md5($pwd)){
        return true;
    }else{
        return false;
    }
}
/**
 * 
 * @param unknown $id
 */
function telphonetool($id){
    $res = db("member")->field("telphone")->find($id);
    return $res['telphone'];
}